﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using SnowEntity;

namespace SnowDAL
{
    public class TopicDAL
    {
        public DataTable QueryReplyByTid(string tid)
        {
            string sql = " select * from reply where tid=" + tid+" order by rid desc";
            return SQLHelper.ExecuteDataSet(sql).Tables[0];
        }

        public DataTable QueryTopicByModule(int module)
        {
            string sql = " select * from topics where state<>-1 and module=" + module;
            if (module == 999)
                sql = " select * from topics where state<>-1 order by tid desc";
            return SQLHelper.ExecuteDataSet(sql).Tables[0];
        }

        public DataTable QueryTopic(string tid)
        {
            string sql = " select * from topics where tid=" + tid;
            return SQLHelper.ExecuteDataSet(sql).Tables[0];
        }

        public int InsertTopic(Topics topic)
        {
            string sql = string.Format("insert into topics values(null,{0},{1},'{2}','{3}','','','{4}',0,{5},0,'')",
                topic.Uid, topic.Module, topic.Title, topic.Content, topic.Time, topic.UV);
            return SQLHelper.ExecuteNonQuery(sql);
        }

        public int DeleteTopic(string tid)
        {
            string sql = "update topics set state=-1 where tid=" + tid;
            return SQLHelper.ExecuteNonQuery(sql);
        }

        public int DeleteReply(string rid)
        {
            string sql = "update reply set state=-1 where rid=" + rid;
            return SQLHelper.ExecuteNonQuery(sql);
        }

        public int UpdateTopic(string tid, string uid, string title, string countent, string time, string module, string uv)
        {
            string sql = string.Format(@"
update topics set uid={0},title='{1}',content='{2}',time='{3}',module={4} ,uv={6} where tid={5}
", uid, title, countent, time, module, tid, uv);
            return SQLHelper.ExecuteNonQuery(sql);
        }

    }
}
